import Draw from '__com/draw/draw.js'

function getOption(info) {
  // image desc avatar estate qrcode phone
  return new Promise((resolve, reject) => {
    let opt = { width: 750, items: [], ratio: 1 }
    let image = new Draw(0, 0, 750)
    image.setImage(info.image, true).then((draw) => {
      // 获取图片后得到高度
      if (draw.height > 1408) {
        draw.height = 1408
      }
      let num = info.highlights?.length || 0
      let lineNum = Math.floor(num / 14)

      let top = draw.bottom()
      opt.height = top + 350 + Math.max(lineNum - 1, 0) * 46
      if (
        info.propertyType == 'industrialPark' ||
        info.propertyType == 'LOFT apartment' ||
        info.propertyType == 'flatApartment'
      )
        opt.height += 60
      opt.items.push(draw) // 添加主图

      let shadow = new Draw(0, top, 750, 200)
      shadow.setShadow(0, -5, '#f5f5f5')
      opt.items.push(shadow) // 添加阴影

      let name = new Draw(40, top + 40)
      name.setPadding(2, 0)
      name.setText(info.propertyName, '#222', 48)
      opt.items.push(name) // 添加姓名

      let type = new Draw(40, top + 112)
      type.setRadius(5).setBackgroundColor('#FFF0C3')
      type.setPadding(13, 13, 10, 13)
      type.setText(info.propertyTypeStr, '#907C3A', 25)
      opt.items.push(type) // 添加类型

      let line = new Draw(40, top + 177, 663, 1)
      line.setBackgroundColor('#ADADAD')
      opt.items.push(line) // 添加分割线

      top = top + 210

      if (info.propertyType == 'industrialPark') {
        let coverAreaT = new Draw(40, top)
        coverAreaT.setPadding(2, 0)
        coverAreaT.setText('占地面积：', '#222', 32)
        opt.items.push(coverAreaT) // 添加占地面积

        let coverAreaV = new Draw(200, top)
        coverAreaV.setPadding(2, 0)
        coverAreaV.setText(info.coverArea + '万㎡', '#F33C3C', 32)
        opt.items.push(coverAreaV) // 添加占地面积值

        let plotRatioT = new Draw(440, top)
        plotRatioT.setPadding(2, 0)
        plotRatioT.setText('容积率：', '#222', 32)
        opt.items.push(plotRatioT) // 添加容积率

        let plotRatioV = new Draw(580, top)
        plotRatioV.setPadding(2, 0)
        plotRatioV.setText(info.plotRatio, '#F33C3C', 32)
        opt.items.push(plotRatioV) // 添加容积率值

        top = top + 60
      }

      let moneyT = new Draw(40, top)
      moneyT.setPadding(2, 0)
      moneyT.setText('总价：', '#222', 32)
      opt.items.push(moneyT) // 添加总价

      let moneyV = new Draw(140, top)
      moneyV.setPadding(2, 0)
      moneyV.setText(info.showTotalPrice, '#F33C3C', 32)
      opt.items.push(moneyV) // 添加总价值

      let areaT = new Draw(440, top)
      areaT.setPadding(2, 0)
      areaT.setText('面积：', '#222', 32)
      opt.items.push(areaT) // 添加面积

      let areaV = new Draw(540, top)
      areaV.setPadding(2, 0)
      areaV.setText(info.showTotalArea, '#F33C3C', 32)
      opt.items.push(areaV) // 添加面积值

      top = top + 60

      if (info.propertyType == 'LOFT apartment' || info.propertyType == 'flatApartment') {
        let isGasT = new Draw(40, top)
        isGasT.setPadding(2, 0)
        isGasT.setText('有无燃气：', '#222', 32)
        opt.items.push(isGasT) // 添加有无燃气

        let isGasV = new Draw(200, top)
        isGasV.setPadding(2, 0)
        isGasV.setText(info.isGasStr, '#F33C3C', 32)
        opt.items.push(isGasV) // 添加有无燃气值

        top = top + 60
      }

      let descT = new Draw(40, top)
      descT.setPadding(2, 0)
      descT.setText('资产亮点：', '#222', 32)
      opt.items.push(descT) // 添加资产亮点

      let descV = new Draw(200, top, 500, 46 * lineNum)
      descV.setPadding(2, 0)
      descV.setText(info.highlights, '#222', 32)
      descV.text.lineNumber = lineNum
      descV.text.lineHeight = 46
      opt.items.push(descV) // 添加资产亮点值

      resolve(opt)
    }, reject)
  })
}

export default {
  getOption
}
